package com.dcdata.common;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.java.Log;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: xinmi
 * @date: 2020/11/23
 * @description:
 */
@Log
public class DateParse {

    public static void main(String[] argc){

        String jsonStr = "{\"busid\":191004,\"tradedatetime\":1575256668000,\"rksj\":1582711258000,\"lineid\":320,\"usertype\":\"00\",\"parsedatetime\":1575262437000,\"isqr\":0,\"stationid\":0}";

        Card card = JSON.parseObject(jsonStr,Card.class);

        Date tradeDate = card.getTradedatetime();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, - 3);
        Date time = c.getTime();

        String preDay = sdf.format(time);

        log.info(preDay);

        log.info(card.toString());

        Calendar c1 = Calendar.getInstance();
        c1.add(Calendar.DATE,-1);
        Date time1 = c1.getTime();
        String preDay1 = sdf.format(time1);
        log.info(preDay1);

    }


    @Data
    @AllArgsConstructor
    public class Card{
        private int busid;
        private Date tradedatetime;
        private Date rksj;
        private int lineid;
        private String usertype;
        private Date parsedatetime;
        private int isqr;
        private int stationid;
    }
}
